<template>
	<view class="search-view">
		<view class="jiapu-search-input-parent">
			<!--家谱搜索-->
			<input class="jiapu-search-input" placeholder="输入家谱号或名称" type="text" confirm-type="search"
			 @confirm="searchXing"  @input="onKeyInput" />
		</view>
		 <view class="list-parent">
			 <view class="list-item"  v-for="(item , index) in list" :key="'item'+index"
				 @click="itemClick" :data-index="item">
				  <!-- 背景 -->
				  <image class="item-bg" src="../../static/icon_iitss_bg.png"></image>
				  <view class="item-view">
					  <view class="item-top-view">
						  <view class="book-cover-view">
							    <image class="book-cover" src="../../static/icon_iitss_book.png" mode="scaleToFill"></image>
						  </view>
						  <view class="content-parent">
							    <text class="shupu-name">{{item.title}}</text>
							    <text class="shupu-faqiren">发起人：{{item.uname}}</text>
							    <text class="shupu-desc">简介：{{item.bio}}</text>
						  </view>
					  </view>
					  <view class="item-bottom-view">
						  <view class="liulan-parent">
							    <text class="txt-liulan">浏览</text>
							    <text class="num-liulan">{{item.browse}}</text>
						  </view>
						  <image class="liulan-line"></image>
						  <view class="riqi-parent">
								<text class="txt-riqi">创建日期</text>
								<text class="data-riqi">{{item.createtime}}</text>
						  </view>
						   <image class="riqi-line"></image>
						  <view class="chakan-view">
								<text v-if="item.status==0" class="btn-chakan">申请</text>
								<text v-if="item.status==1" class="btn-chakan">查看</text>
								<text v-if="item.status==2" class="btn-chakan">申请中</text>
						  </view>
					  </view>
				  </view>
			 </view>
		 </view>
	<LoginTipDialog :isShow="isShowLoginTip" dataSource="登录查看具体信息"  @returnLoginTipDialog="returnLoginTipDialog"/>
	</view>
</template>

<script>
	import request from '../index/request.js';
	import LoginTipDialog from "@/components/login-tip-dialog/login-tip-dialog.vue";
	export default {
		components: {
			LoginTipDialog
		},
		data() {
			return {
				list:[],
				page:1,
				searchKey:"",
				isShowLoginTip:false,
			}
		},
		methods: {
			onLoad:function(options){
				this.appUtil.saveAppInviteId(options)
			},
			onShow:function(){
				this.share.url='/pages/tabBar/home/index?appInviteId='+this.appUtil.getAppInviteId()
				this.share.shareType=1
			},
			searchXing:function(){
				var user=uni.getStorageSync("shiqin-user")
				if(!user.PQD){
					this.isShowLoginTip=true
				}else{
					uni.startPullDownRefresh()
				}
			},
			returnLoginTipDialog:function(e){
				this.isShowLoginTip=e.isclose
				if(e.tag){
					uni.navigateTo({
						url:"../index/index"
					})
				}
			},
			onKeyInput: function(event) {
				this.searchKey = event.target.value
			},
			onShow:function(){
				var user=uni.getStorageSync("shiqin-user")
				if (!user.PQD) {
					this.isShowLoginTip=true
				}
				if(this.list.length==0){
					uni.startPullDownRefresh()
				}
			},
			//下拉刷新
			onPullDownRefresh:function(){
				this.page=1
				this.getData()
			},
			//上拉加载更多
			onReachBottom:function(){
				this.page=this.page+1
				this.getData()
			},
			//获取数据
			getData:function(){
				var that=this
				request.post("api/common/seekpedigree_list",{
					type:"0",
					page:this.page,
					area:"",
					keyword:this.searchKey
				}).then(data=>{
					uni.stopPullDownRefresh()
					if(that.page==1){
						this.list=data;
					}else{
						for (var i = 0; i < data.length; i++) {
							this.list.push(data[i]);
						}
					}
					
				})
			},
			itemClick:function(e){
				let item = e.currentTarget.dataset.index;
				var user=uni.getStorageSync("shiqin-user")
				if(!user.PQD){
					this.isShowLoginTip=true
				}else{
					uni.navigateTo({
						url: "../jiapu-detail/index?id="+ item.id
					})
				}
			}
		}
	}
</script>

<style>
	@import "index.css";
</style>
